function checkSubmit(){
  let name = document.querySelector('[name="name"]');
  let price = document.querySelector('[name="price"]');

  if(name.value.trim()==''){
    alert('请输入水果名称！');
    name.focus();
    return false;
  }

  if(price.value.trim()==''){
    alert('请输入水果单价！');
    price.focus();
    return false;
  }
  return true;

}

function upload(file){
  let img = file.nextElementSibling;
  let thumb = img.nextElementSibling;
  let xhr = new XMLHttpRequest();
  
  xhr.responseType='json';
  xhr.onreadystatechange = function(){
    if(xhr.readyState===4){
      if(xhr.status===200){
        if(img && thumb){
          let { path } = xhr.response
          img.src = path;
          thumb.value = path;
        }
      }
    }
  }
  xhr.open('post','/upload');
  let form = new FormData();
  form.append('upfile', file.files[0]);
  xhr.send(form)
}